import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/',
    redirect: '/payment',
    open: true,
    // hidden: true
  },
  {
    path: '/login',
    // redirect: '/login',
    open: true,
    menuId: '1',
    component: () => import('@/views/login/index'),
    // hidden: true
  },
  {
    path: '/404',
    open: true,
    menuId: '1',
    component: () => import('@/views/error/page404'),
    // hidden: true
  },
  {
    path: '/mianSing',
    // redirect: '/login',
    open: true,
    menuId: '1',
    component: () => import('@/views/mainSing/index'),
    // hidden: true
  },
  {
    path: '/payment',
    redirect: '/payment/payment',
    menuId: '100',
    component: Layout,
    meta: { title: '费用管理', icon: 'form' },
    children: [
      {
        path: 'payment',
        name: 'payment',
        menuId: '101',
        component: () => import('@/views/pay/index'),
        meta: { title: '报单列表', icon: 'form' }
      },
      {
        path: 'cost',
        name: 'cost',
        menuId: '102',
        component: () => import('@/views/pay/cost'),
        meta: { title: '店务支出', icon: 'form' }
      },
      {
        path: 'salary',
        name: 'salary',
        menuId: '103',
        component: () => import('@/views/pay/salary'),
        meta: { title: '工资列表', icon: 'form' }
      },
    ]
  },
  
  {
    path: '/lessionSet',
    redirect: '/lessionSet/lession',
    component: Layout,
    menuId: '200',
    meta: { title: '课程设置', icon: 'form' },
    children: [
      {
        path: 'lession',
        name: 'lession',
        menuId: '201',
        component: () => import('@/views/lessions/lessionsList'),
        meta: { title: '课程列表', icon: 'form' }
      },
      {
        path: 'type',
        name: 'type',
        menuId: '202',
        component: () => import('@/views/lessions/lessionType'),
        meta: { title: '类型列表', icon: 'form' }
      },
      {
        path: 'card',
        name: 'card',
        menuId: '203',
        component: () => import('@/views/lessions/lessionCard'),
        meta: { title: '卡列表', icon: 'form' }
      },
    ]
  },
  {
    path: '/lessionMg',
    redirect: '/lessionMg/lessiontypecard',
    component: Layout,
    menuId: '300',
    meta: { title: '课程管理', icon: 'form' },
    children: [
      {
        path: 'lessiontypecard',
        name: 'lessiontypecard',
        menuId: '301',
        component: () => import('@/views/pay/settingPay'),
        meta: { title: '学费设置', icon: 'form' }
      },
      {
        path: 'classPlan',
        name: 'classPlan',
        menuId: '302',
        component: () => import('@/views/lessions/classPlan'),
        meta: { title: '课程表', icon: 'form' }
      },
      {
        path: 'level',
        name: 'level',
        menuId: '303',
        component: () => import('@/views/lessions/level'),
        meta: { title: '考级记录', icon: 'form' }
      },
    ]
  },
  {
    path: '/classMg',
    redirect: '/classMg/classList',
    component: Layout,
    menuId: '1100',
    meta: { title: '班级管理', icon: 'form' },
    children: [
      {
        path: 'classList',
        name: 'classList',
        menuId: '1101',
        component: () => import('@/views/classMg/classList'),
        meta: { title: '班级列表', icon: 'form' }
      }
    ]
  },
  {
    path: '/testMg',
    redirect: '/test/testList',
    component: Layout,
    menuId: '1000',
    meta: { title: '考试管理', icon: 'form' },
    children: [
      {
        path: 'testList',
        name: 'testList',
        menuId: '1001',
        component: () => import('@/views/testMg/testList'),
        meta: { title: '考试列表', icon: 'form' }
      }
    ]
  },
  {
    path: '/employeeMg',
    redirect: '/employeeMg/employee',
    component: Layout,
    menuId: '400',
    meta: { title: '人员管理', icon: 'form' },
    children: [
      {
        path: 'employee',
        name: 'employee',
        menuId: '401',
        component: () => import('@/views/person/teacher'),
        meta: { title: '教师列表', icon: 'form' }
      },
      {
        path: 'student',
        name: 'student',
        menuId: '402',
        component: () => import('@/views/person/student'),
        meta: { title: '学生列表', icon: 'form' }
      },
    ]
  },
  {
    path: '/sign',
    redirect: '/sign/sign',
    component: Layout,
    menuId: '500',
    meta: { title: '签到管理', icon: 'form' },
    children: [
      {
        path: 'sign',
        name: 'sign',
        menuId: '501',
        component: () => import('@/views/sign/index'),
        meta: { title: '签到列表', icon: 'form' }
      },
      {
        path: 'signlog',
        name: 'signlog',
        menuId: '502',
        component: () => import('@/views/sign/signLog'),
        meta: { title: '历史签到', icon: 'form' }
      },
    ]
  },
  {
    path: '/mobileSet',
    redirect: '/mobileSet/h5user',
    component: Layout,
    menuId: '600',
    meta: { title: 'H5设置', icon: 'form' },
    children: [
      {
        path: 'h5user',
        name: 'h5user',
        menuId: '601',
        component: () => import('@/views/user/h5user'),
        meta: { title: 'H5用户管理', icon: 'form' }
      },
      {
        path: 'picture',
        name: 'Picture',
        menuId: '602',
        component: () => import('@/views/mobileSet/picture'),
        meta: { title: 'H5主页轮播图', icon: 'form' }
      },
      {
        path: 'video',
        name: 'Video',
        menuId: '603',
        component: () => import('@/views/mobileSet/video'),
        meta: { title: 'H5主页视频', icon: 'form' }
      },
      {
        path: 'notice',
        name: 'notice',
        menuId: '604',
        component: () => import('@/views/mobileSet/notice'),
        meta: { title: '公告', icon: 'form' }
      }
    ]
  },
  {
    path: '/system',
    redirect: '/system/tenantList',
    component: Layout,
    menuId: '700',
    meta: { title: '系统管理', icon: 'form' },
    children: [
      {
        path: 'tenantList',
        name: 'tenantList',
        menuId: '701',
        component: () => import('@/views/user/TenantList'),
        meta: { title: '机构列表', icon: 'form' }
      },
      {
        path: 'roleList',
        name: 'roleList',
        menuId: '702',
        component: () => import('@/views/user/RoleList'),
        meta: { title: '角色列表', icon: 'form' }
      },
      {
        path: 'adminUsers',
        name: 'adminUsers',
        menuId: '703',
        component: () => import('@/views/user/admin'),
        meta: { title: '管理员列表', icon: 'form' }
      },
      {
        path: 'operationLog',
        name: 'operationLog',
        menuId: '704',
        component: () => import('@/views/user/operLog'),
        meta: { title: '用户操作记录', icon: 'form' }
      }
    ]
  },
  {
    path: '/product',
    redirect: '/product/productList',
    component: Layout,
    menuId: '800',
    meta: { title: '商品管理', icon: 'form' },
    children: [
      {
        path: 'productList',
        name: 'productList',
        menuId: '801',
        component: () => import('@/views/product/productList'),
        meta: { title: '商品列表', icon: 'form' }
      },
      {
        path: 'productCate',
        name: 'productCate',
        menuId: '802',
        component: () => import('@/views/product/productCate'),
        meta: { title: '商品分类', icon: 'form' }
      },
      {
        path: 'salesLog',
        name: 'salesLog',
        menuId: '803',
        component: () => import('@/views/product/salesLog'),
        meta: { title: '销售记录', icon: 'form' }
      },
    ]
  },
  {
    path: '/dataTj',
    redirect: '/dataTj/payTj',
    component: Layout,
    menuId: '900',
    meta: { title: '数据统计', icon: 'form' },
    children: [
      {
        path: 'payTj',
        name: 'payTj',
        menuId: '901',
        component: () => import('@/views/dataTj/payTj'),
        meta: { title: '收支统计', icon: 'form' }
      },
      {
        path: 'cancelLessTj',
        name: 'cancelLessTj',
        menuId: '902',
        component: () => import('@/views/dataTj/cancelLessTj'),
        meta: { title: '消课统计', icon: 'form' }
      },
      {
        path: 'lessionTj',
        name: 'lessionTj',
        menuId: '903',
        component: () => import('@/views/dataTj/lessionTj'),
        meta: { title: '课程统计', icon: 'form' }
      }
    ]
  }
];

// 解决重复点击导航路由报错
const originalPush = Router.prototype.push;
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err);
}

const createRouter = () => new Router({
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
});

const router = createRouter();

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

// router.beforeEach((to, from, next) => {
//   if(to.path !== "/login") {
//     sessionStorage.getItem('isLogin')*1?next():next('/login')
//   }else {
//     next()
//   }
// })
export default router
